<?php

namespace StudyBuddy\Controllers;


use StudyBuddy\Responder;
use StudyBuddy\Request;
use StudyBuddy\WebPage;

/**
 * This controller class is usually called
 * via ajax to get the quick registration form html
 *
 */
class Getsubject extends WebPage
{


	protected function main(){
                $subject1 = array(
                    4 => 'Maths',
                    5 => 'Science'
                );
                $subject2 = array(
                    6 => 'Maths',
                    7 => 'Science'
                );
                $subject3 = array(
                    1 => 'E Maths',
                    2 => 'A Maths',
                    3 => 'Physics'
                );
		d('cp');
		
                $subject = null;
                switch ($this->oRequest['s_id']) {
                    case 1:
                        $subject = $subject1;
                        break;
                    case 2:
                        $subject = $subject2;
                        break;
                    case 3:
                        $subject = $subject3;
                        break;
                    default:
                        break;
                }
                
                $current = '';
                $s = '
                    <select name="subject" onchange="oSL.getChapter(this.options[this.selectedIndex].value)" style="border:none; background:transparent; padding:0 3px 3px 0; width:86px; position:relative">
                        <option value="">All Subject</option>';
                
                $tpl = '<option value="%1$s"%2$s>%3$s</option>';
				if($subject != null) {
					foreach($subject as $key => $val){
							$selected = ($key == $current) ? ' selected="selected"' : '';
							$s .= vsprintf($tpl, array($key, $selected, $val));
					}
				}
                
                $s .= '
                    </select>
                    <span style="position:absolute; float:right; bottom:0; right:0; width:24px; height:24px; background-color:#ff8e33"></span>';
                
		$aSubject = array('subject' => $s);

		Responder::sendJSON($aSubject);
	}
}